import csv

# 输入和输出CSV文件的路径
input_csv_path = 'data_rte.csv'
output_csv_path = 'data_rte_en.csv'

# 读取输入CSV文件并替换字符串
with open(input_csv_path, mode='r', newline='', encoding='utf-8') as infile, open(output_csv_path, mode='w', newline='',
                                                                                  encoding='utf-8') as outfile:
    csv_reader = csv.reader(infile)
    csv_writer = csv.writer(outfile)

    entity_ch = ['检查项目', '科室', '疾病', '药品', '食物', '症状']
    entity_en = ['Check', 'Department', 'Disease', 'Drug', 'Food', 'Symptom']

    relation_ch = ['属于科室', '存在常用药品', '存在推荐药品', '存在宜吃食物', '存在推荐食谱', '存在忌吃食物', '存在所需检查', '存在症状', '存在并发症']
    relation_en = ['belongs_to', 'common_drug', 'recommend_drug', 'do_eat', 'recommend_eat', 'no_eat', 'need_check', 'has_symptom', 'accompany_with']

    # 遍历CSV文件的每一行并替换字符串
    for row in csv_reader:
        # 假设第一项是字符串且需要替换
        for i in {0, 3}:
            if row and isinstance(row[i], str):
                for j in range(len(entity_ch)):
                    if entity_ch[j] in row[i]:
                        row[i] = row[i].replace(entity_ch[j], entity_en[j])
        i = 2
        if row and isinstance(row[i], str):
            for j in range(len(relation_ch)):
                if relation_ch[j] in row[i]:
                    row[i] = row[i].replace(relation_ch[j], relation_en[j])
        csv_writer.writerow(row)

input_csv_path = 'data_att.csv'
output_csv_path = 'data_att_en.csv'
with open(input_csv_path, mode='r', newline='', encoding='utf-8') as infile, open(output_csv_path, mode='w', newline='',
                                                                                  encoding='utf-8') as outfile:
    csv_reader = csv.reader(infile)
    csv_writer = csv.writer(outfile)

    att_ch = ['疾病名称', '疾病简介', '疾病病因', '预防措施', '治疗周期', '治疗方式', '治愈概率', '疾病易感人群']
    att_en = ['name', 'desc', 'cause', 'prevent', 'cure_lasttime', 'cure_way', 'cured_prob', 'eay_get']

    # 遍历CSV文件的每一行并替换字符串
    for row in csv_reader:
        # 假设第一项是字符串且需要替换
        i = 1
        if row and isinstance(row[i], str):
            for j in range(len(att_ch)):
                if att_ch[j] in row[i]:
                    row[i] = row[i].replace(att_ch[j], att_en[j])
        csv_writer.writerow(row)

print(f"CSV文件已处理")
